﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VarianceReportWinUI
{
    public class WorkQueue
    {
        private const string WorkQueueFileName = ".\\WorkQueue.xml";
        private List<WorkItem> mWorkItemList;
        private List<Filter> mFilterList;

        public List<WorkItem> WorkItemList
        {
            get
            {
                return mWorkItemList;
            }
            set
            {
                mWorkItemList = value;
            }
        }

        public List<Filter> FilterList
        {
            get
            {
                return mFilterList;
            }
            set
            {
                mFilterList = value;
            }
        }

        public WorkQueue()
        {
        }

        public WorkQueue(bool pInit)
        {
            mWorkItemList = new List<WorkItem>();
        }

        public static WorkQueue Load()
        {
            if (!System.IO.File.Exists(WorkQueue.WorkQueueFileName))
            {
                return new WorkQueue(true);
            }
            else
            {
                return (WorkQueue)Serializer.FromXml(System.IO.File.ReadAllText(WorkQueue.WorkQueueFileName), typeof(WorkQueue));
            }
        }

        public string Save()
        {
            string tResult = "";

            try
            {
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(WorkQueue.WorkQueueFileName))
                {
                    sw.Write(Serializer.ToXml(this, typeof(WorkQueue)));
                    sw.Close();
                }
            }
            catch (Exception exc)
            {
                tResult = exc.Message;
            }
            return tResult;
        }

    }
}
